#系统随机生成8个1-33的整数形成一注中奖号码，用户在控制台输入8位数字看是否中奖：
# 导入库 随机生成八个1-33之间的数字
# 用户输入八个数字
# 判断有几个与中间数字一样 输出 算中奖比例
import random

def generate_lottery_numbers():
    """生成一组随机的中奖号码"""
    return random.sample(range(1, 34), 8)


def check_winning(user_numbers, winning_numbers):
    """检查用户输入的号码与中奖号码是否中奖"""
    count_difference = sum(1 for x, y in zip(user_numbers, winning_numbers) if x != y)

    if count_difference == 0:
        return "一等奖"
    elif count_difference == 1:
        return "二等奖"
    elif count_difference == 2:
        return "三等奖"
    elif count_difference == 3:
        return "四等奖"
    else:
        return "未中奖"


def simulate_lottery_draw(winning_numbers, num_tickets=10000):
    """模拟购买多张彩票并计算中奖情况"""
    results = {"一等奖": 0, "二等奖": 0, "三等奖": 0, "四等奖": 0, "未中奖": 0}

    for _ in range(num_tickets):
        user_numbers = generate_lottery_numbers()
        winning_class = check_winning(user_numbers, winning_numbers)
        results[winning_class] += 1

    return results


def main():
    # 生成中奖号码
    winning_numbers = generate_lottery_numbers()
    print("中奖号码:", winning_numbers)

    # 用户输入号码
    user_input = input("请输入8位数字，用空格分隔：")
    user_numbers = list(map(int, user_input.split()))

    # 检查用户输入的号码是否中奖
    result = check_winning(user_numbers, winning_numbers)
    print("您的中奖结果是：", result)

    # 模拟购买10000张彩票的中奖情况
    simulation_results = simulate_lottery_draw(winning_numbers)
    print("\n模拟购买10000张彩票的中奖情况:")
    for prize, count in simulation_results.items():
        print(f"{prize}: {count} 张")


if __name__ == "__main__":
    main()

